import 'package:flutter/material.dart';
import 'package:xvideos/assets_tool/images.dart';
import 'package:xvideos/hj_page/home_business/widget/user_award_view.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';
import 'package:xvideos/routers/jump_router.dart';
import 'package:xvideos/tools_base/image/custom_network_image.dart';
import 'package:xvideos/tools_base/widget/follow_button.dart';
import 'package:video_player/video_player.dart';

import '../../../hj_model/video_model.dart';
import '../../../tools_base/widget/net_image_widget.dart';
import '../../home_business/widget/user_name_view.dart';

class VideoUserInfoWidget extends StatefulWidget {
  final VideoModel? videoModel;
  final VideoPlayerController? controller;

  const VideoUserInfoWidget({
    super.key,
    this.videoModel,
    this.controller,
  });

  @override
  State<StatefulWidget> createState() {
    return _VideoUserInfoWidgetState();
  }
}

class _VideoUserInfoWidgetState extends State<VideoUserInfoWidget> {
  VideoModel? get videoModel => widget.videoModel;

  bool get hasFollowed => videoModel?.publisher?.hasFollowed ?? false;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 44,
      margin: EdgeInsets.only(bottom: 6),
      child: Row(
        children: [
          InkWell(
            onTap: () {
              widget.controller?.pause();
              Navigator.pop(context);
            },
            child: Container(
              padding: EdgeInsets.only(left: 0),
              child: Icon(
                Icons.arrow_back_ios,
                color: Colors.white,
              ),
            ),
          ),
          if (videoModel != null) ...[
            InkWell(
              onTap: () {
                widget.controller?.pause();
                pushToPersonCenter(videoModel?.publisher?.uid);
              },
              child: Container(
                padding: EdgeInsets.only(left: 8),
                child: NetworkImageLoader(
                  imageUrl: videoModel?.publisher?.portrait ?? "",
                  borderRadius: 20,
                  width: 38,
                  height: 38,
                ),
              ),
            ),
            const SizedBox(width: 12),
            Expanded(
              child: GestureDetector(
                onTap: () {
                  widget.controller?.pause();
                  pushToPersonCenter(videoModel?.publisher?.uid);
                },
                child: Row(
                  children: [
                    UserNameView(
                      name: videoModel?.publisher?.name ?? "",
                      isVip: (videoModel?.publisher?.vipLevel ?? 0) > 0,
                    ),
                    if ((videoModel?.publisher?.vipLevel ?? 0) > 0) ...[
                      4.sizeBoxW,
                      Image.asset('hg_icon.webp'.commonImgPath, width: 18, height: 18),
                    ],
                    UserAwardView(
                      awards: videoModel?.publisher?.awards,
                      size: 18,
                    ),
                  ],
                ),
              ),
            ),
            12.sizeBoxW,
            FollowButton(
              mediaId: (videoModel?.publisher?.uid ?? 0).toString(),
              isFollow: videoModel?.publisher?.hasFollowed,
              followType: FollowEnum.user,
              successsAction: (isSuccess) => videoModel?.publisher?.hasFollowed = isSuccess,
            ),
          ],
        ],
      ),
    );
  }
}
